<template>
  <div>
    <van-popup
      v-model="isShowLink"
      round
      position="bottom"
      :duration="duration"
      :close-on-click-overlay="false"
      @click-overlay="cancel"
    >
      <div class="top">
        <div class="cancel" @click="cancel">取消</div>
        <div class="popup-title">添加链接</div>
        <div class="sure" @click="confirm">确定</div>
      </div>
      <div class="form">
        <van-field
          v-model="linkForm.linkName"
          label-width="0"
          name=""
          label=""
          placeholder="链接名称（选填）"
        />
        <van-field
          v-model="linkForm.link"
          label-width="0"
          name="url"
          label=""
          placeholder="http：//"
        />
      </div>
    </van-popup>
  </div>
</template>

<script>
export default {
  props: {
    isShowLink: {
      type: Boolean,
    },
    duration: {
      type: Number,
    },
  },
  data() {
    return {
      linkForm: {
        linkName: "",
        link: "",
      },
    };
  },
  watch: {
    isShowLink(newval, oldVal) {
      this.linkForm = {
        linkName: "",
        link: "",
      };
    },
  },
  methods: {
    //添加链接
    confirm() {
      if (this.linkForm.linkName == "") return this.$Toast("链接名称不能为空");
      if (this.linkForm.link == "") return this.$Toast("链接地址不能为空");
      this.$emit("confirm", this.linkForm);
    },
    //关闭链接弹窗
    cancel() {
      this.linkForm = {
        linkName: "",
        link: "",
      };
      this.$emit("cancel", false);
    },
  },
};
</script>

<style lang="scss" scoped>
.top {
  padding: 32px;
  line-height: 33px;
  font-weight: 400;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .cancel {
    font-size: 28px;
    color: #999999;
  }
  .popup-title {
    font-size: 28px;
    color: #333333;
  }
  .sure {
    font-size: 28px;
    color: #025ce0;
  }
}
.form {
  padding: 48px 0px;
  ::v-deep .van-field__value {
    background-color: #f6f6f6;
    padding: 32px;
    border-radius: 16px;
    font-size: 28px;
  }
}
</style>